<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
  <!-- 引入jq文件 -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 引入bootstrap的js文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" />
        <input type="password" class="input_pass" placeholder="密码" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>

  <!-- 添加模态框 -->
  <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">温馨提示</h4>
        </div>
        <div class="modal-body">
          <p></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">确认</button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

</body>

</html>
<script src="./js/https.js"></script>
<script>
  $(function () {
    //  给登录按钮设置点击事件
    $('.input_sub').click(function (e) {
      // 阻止默认事件
      e.preventDefault();
      // 获取内容
      let txt = $('.input_txt').val().trim();
      let pass = $(".input_pass").val().trim();
      if (txt == '' || pass == '') {
        // alert("账号与密码不能为空");
        $('.modal-body').text("用户或密码不能为空")
        $('#myModal').modal()
        return;
      }
      // 发起ajax请求
      $.ajax({
        type: "post",
        url: BigNew.user_login,
        data: {
          username: txt,
          password: pass
        },
        success: (res) => {
          if (res.code == 200) {
            // 保存后台返回的token
            localStorage.setItem('token23', res.token);
            
            // alert(res.msg);  原生的弹窗会卡住代码的执行

             // 显示模态框,注意不会卡住代码的执行
            $('.modal-body').text(res.msg)
            $('#myModal').modal()
            // 当模态框被(关闭)隐藏的时候,才跳转页面
            $('#myModal').on('hidden.bs.modal', function (e) {
              // 当模态框被隐藏之后会执行这里的代码
              //  跳转到主页
              window.location = './index.html'
            })
          } else {
            // 当账户密码错误的显示模态框
            $('.modal-body').text(res.msg)
            $('#myModal').modal()
            $('.input_txt').val('')
            $('.input_pass').val('')
          }
        }
      })
    })
  })
</script>